package com.xu.demo.observerPattern;

public class ObserverPattern {

    public static void main(String[] args) {

        //1.创建主题对象
        SubscriptionSubject subject = new SubscriptionSubject();
        Observer ronnie = new ConcreteObserver("Ronnie");
        Observer ding = new ConcreteObserver("Ding");
        Observer trump = new ConcreteObserver("Trump");

        //2.观察者订阅主题
        subject.attach(ronnie);
        subject.attach(ding);
        subject.attach(trump);

        //3.更新主题
        subject.notify("Java专栏更新了！");

        System.out.println("====================我是分割线==================");
        //4.观察者取消订阅主题
        subject.detach(ding);
        subject.detach(trump);

        //5.更新主题
        subject.notify("Python专栏更新了！");

    }

}
